     window.fbAsyncInit = function() {
        // init the FB JS SDK
        FB.init({
          appId      : &#39;645356518812956&#39;, // App ID from the App Dashboard
          status     : true, // check the login status upon init?
          cookie     : true, // set sessions cookies to allow your server to access the session?
          xfbml      : true,  // parse XFBML tags on this page?
          frictionlessRequests: true,
          oauth  : true  /* oAuth is required now */
        });
        // Additional init code here
      }
      function login() {
        FB.login(function(response) {
          if (!response || response.error) {
            window.location.reload();
          } else if (response.authResponse) {
            // connected
          }
            else {
              // cancelled
            }
        }
                 //  ask for  {
                 //   these permissions  when needed   scope: &#39;publish_stream&#39;}
                );}  
      function checkStatus(){
        FB.login(function(response) {
          console.log(response);
        }, {scope: &#39;publish_stream&#39;});
           }
                 // Load the SDKs source Asynchronously
                 // Note that the debug version is being actively developed and might
                 // contain some type checks that are overly strict.
                 // Please report such bugs using the bugs tool.
                 (function(d, debug){
                   var js, id = &#39;facebook-jssdk&#39;, ref = d.getElementsByTagName(&#39;script&#39;)[0];
                   if (d.getElementById(id)) {
                     return;
                   }
                   js = d.createElement(&#39;script&#39;); js.id = id; js.async = true;
                                        js.src = &#39;//connect.facebook.net/en_US/all&quot; + (debug ? &quot;/debug&quot; : &quot;) + &quot;.js&#39;;
                                        ref.parentNode.insertBefore(js, ref);
                 }
                  (document, /*debug*/ false));
        $(function(){
          $( &quot;.imgToPost&quot; ).hover(
            function() {
              $(&quot;.postIt&quot;).click(function() {
                checkStatus();
                var fav = $(this).parentsUntil(&quot;.separator&quot;).find(&quot;img:not(.gif)&quot;).attr(&#39;src&#39;);
                                                                                                            $(&#39;#sourceHolder&#39;).html(fav);
                                                                                                            $(&#39;#uploadingPhoto,#userInput&#39;).empty();
                                                                                                            $(&quot;.photo-uploader&quot;).fadeToggle(500);
                var photoToUpload = document.getElementById(&#39;uploadingPhoto&#39;);
                                                            var userComment = document.getElementById(&#39;userInput&#39;);
                                                            var inputBox = document.createElement(&quot;textarea&quot;);
                var oImg=document.createElement(&quot;img&quot;);
                var imgURL = document.getElementById(&quot;sourceHolder&quot;);
                oImg.src = fav;
                oImg.className = &#39;funnyPhoto&#39;;
                inputBox.className = &#39;userMessage&#39;;
                inputBox.placeholder = &#39;Say something about this photo ...&#39;;
                inputBox.autofocus = &#39;autofocus&#39;;
                photoToUpload.appendChild(oImg);
                userComment.appendChild(inputBox);
              });   });
        });
        function post() {
          var imgURL = document.getElementById(&quot;sourceHolder&quot;);
          var userMessage = $(&quot;.userMessage&quot;).val();
          FB.api(&#39;/me/photos&#39;, &#39;post&#39;, {
                 message: userMessage,
                 url: imgURL.innerHTML        
                 }, function(response){
            if (!response || response.error) {
              if (response.status === &#39;connected&#39;) {
                  window.location.reload();
            }   
            else if ( response.status === &#39;not_authorized&#39;) {
                     login()
              }
              else {
                login()
              }  
          } else {
            confirmPost();
          }
        });
      }
      FB.Event.subscribe(&#39;auth.login&#39;, function(response) {
                         window.location.reload();
      });
      function postToPage() {
        var imgURL = document.getElementsByTagName(&quot;img&quot;)[0].src;
        var wallPost = {
          access_token: &quot;CAAJK8sYOrRwBAHUCFdmCGpuy7yRl2MciWsVFQTYv36oLQLEJBVv6ZB3K6L29ZBqjcAdhdTe0v8mhPsbjAeZCuFyQiYs9KZB2Kz7ELhJQMbW5KvHGK2xeB8IZBKvuapybjp4NyfGiB0F8U3kKAxq2JTbZBeFqofxu77WN7tverLl2YJtZCwDG27OkpSdldZBRAQYZD&quot;,
          url: imgURL
        };
        FB.api(&#39;/me/photos&#39;, &#39;post&#39;, wallPost, function(response) {
               if (!response || response.error) {
          alert(&#39;Error occurred&#39;);
                } else {
                $(document).ready(function() {
            $(&quot;.confirmScreen&quot;).fadeIn(&quot;slow&quot;).delay(2500).fadeOut(&quot;fast&quot;);
          });
        }
      });
      }